package com.efounder.util;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.view.WindowManager;

import com.efounder.util.AppContext;

/**
 * Created by hudq on 2016/11/13.
 */

public class DialogUtils {

    private static ProgressDialog progressDialog;

    public static void showProgressDialog(){
        showProgressDialog("正在初始化数据...");
    }

    public static void showProgressDialog(String message){
        synchronized (DialogUtils.class){
            if (progressDialog == null){
                progressDialog = new ProgressDialog(AppContext.getCurrentActivity());
                progressDialog.setMessage(message);
                progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                progressDialog.setCanceledOnTouchOutside(true);
                progressDialog.setCancelable(true);
                progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        progressDialog = null;
                    }
                });
            }
            progressDialog.show();

        }
    }
    public void showProgress(String message){
        showProgressDialog(message);
    }

    public void showProgress(){
        showProgress("正在初始化数据...");
    }

    public static void dismissProgressDialog(){
        synchronized (DialogUtils.class){
            try {
                if (progressDialog != null && progressDialog.isShowing()){
                    progressDialog.dismiss();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                progressDialog = null;
            }
        }
    }

    public void dismissProgress(){
        dismissProgressDialog();
    }





}
